﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App3"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:Core="using:Microsoft.Xaml.Interactions.Core" x:Name="page"
    x:Class="App3.MainPage"
    mc:Ignorable="d">
    <Page.DataContext>
        <local:ViewModel/>
    </Page.DataContext>

	<Grid>
        <Grid.Background>
            <SolidColorBrush Color="{Binding Selected}"/>
        </Grid.Background>
        <ScrollViewer Width="400" Height="500" Background="White">
			<ItemsControl ItemsSource="{Binding Colors}">
				<ItemsControl.ItemsPanel>
					<ItemsPanelTemplate>
						<WrapGrid Orientation="Horizontal" />
					</ItemsPanelTemplate>
				</ItemsControl.ItemsPanel>
				<ItemsControl.ItemTemplate>
					<DataTemplate>
						<Grid Height="50" Width="50">
							<Grid.Background>
								<SolidColorBrush Color="{Binding}" />
							</Grid.Background>
							<Interactivity:Interaction.Behaviors>
								<Core:EventTriggerBehavior EventName="PointerPressed">
									<Core:ChangePropertyAction TargetObject="{Binding DataContext, ElementName=rectangle}" PropertyName="Selected" Value="{Binding Mode=OneWay}"/>
								</Core:EventTriggerBehavior>
							</Interactivity:Interaction.Behaviors>
							<Rectangle x:Name="rectangle" DataContext="{Binding DataContext, ElementName=page}" />
						</Grid>
					</DataTemplate>
				</ItemsControl.ItemTemplate>
			</ItemsControl>
		</ScrollViewer>
	</Grid>
</Page>
